package com.example.evanproject.controller;


import com.example.evanproject.service.impl.NewsServiceImpl;
import com.example.evanproject.util.AjaxResult;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/new")
@CrossOrigin
public class NewController {
    @Autowired
    private NewsServiceImpl newService;
//   获取所有的新闻（分页以及搜索）
    @RequestMapping("/selectinfolist")
    public AjaxResult selectall(String title, String time1, String time2, Integer typeid, Integer pageNum, Integer pageSize){
        return AjaxResult.success(newService.selectall(title,time1,time2,typeid, pageNum,pageSize));
    }
    @RequestMapping("/selectinfolist2")
    public AjaxResult selectall2(){
        return AjaxResult.success(newService.selectall2());
    }


    //获取所有的新闻列表（前台的推优（以后可以按照今天来推 目前没有实现））

    @RequestMapping("/selectall")
    public AjaxResult selectalllist(HttpServletRequest httpServletRequest){
        return AjaxResult.success(newService.selectalllist());
    }

//    获取某个新闻的详情
    @RequestMapping("selectnewbyid")
    public AjaxResult  selectnewbyid(Integer newId){
     return AjaxResult.success(newService.selectnewbyid(newId));
    }


//    添加新闻
    @RequestMapping("addnew")
    public AjaxResult addnew(String iTitle,String iAuthor,String iContent,Integer typeId){
        System.out.println("调用接口");


        return AjaxResult.success( newService.addnew(iTitle,iAuthor,iContent,typeId));
    }
}
